require(['monitor'], function () {

    $('#monitor').monitor({
        canId: '11',
        callback: function (data) {
            loadData(data);
        },
        clearData: function () {
            loadData({});
        }
    });

    function loadData(data) {
        if (!$.isEmptyObject(data)) {
            $("#totalVoltage").html(data.totalVoltage || '-' + "V");
            $("#totalElectricCurrent").html(data.totalElectricCurrent || '-' + "A");
            $("#soc").html(data.soc || '-' + "%");
            $("#highestBatteryVoltage").html(data.highestBatteryVoltage || '-' + "V");
            $("#lowestBatteryVoltage").html(data.lowestBatteryVoltage || '-' + "V");
            $("#highestTemperature").html(data.highestTemperature || '-' + "℃");
            $("#lowestTemperature").html(data.lowestTemperature || '-' + "℃");
            var sign = data.batteryStatus.charAt(5);
            if (sign == '1') {
                $("#isLink").html("充电");
            } else {
                $("#isLink").html("未连接");
            }
            $("#batteryManageSysLife").html(data.batteryManageSysLife || '-');
            //最高单体电压
            var highVoltage = data.monomerVltList;
            var highVoltageAr = highVoltage.split("/")
            var highVoltageBox = data.vltBoxNOList;
            var highVoltageBoxAr = highVoltageBox.split("/");
            var highVoltageNum = data.vltLocList;
            var highVoltageNumAr = highVoltageNum.split("/")
            //最低单体电压
            var lowVoltageAr = data.monomerLowVltList.split("/");
            var lowVoltageBoxAr = data.lowVltBoxNOList.split("/");
            var lowVoltageNumAr = data.lowVltLocList.split("/");
            //最高单体温度
            var highTemprtAr = data.monomerTeptList.split("/");
            var highTemprtBoxAr = data.teptBoxNoList.split("/");
            var highTemprtNumAr = data.teptLocList.split("/");
            //最低单体温度
            var lowTemprtAr = data.monomerLowTeptList.split("/");
            var lowTemprtBoxAr = data.lowTeptBoxNoList.split("/");
            var lowTemprtNumAr = data.lowTeptLocList.split("/");

            for (var i = 1; i <= 4; i++) {
                if (highVoltageAr[i - 1]) {
                    $("#highestVoltageVal" + i).html(highVoltageAr[i - 1] + "V");
                }
                if (highVoltageNumAr[i - 1] && highVoltageBoxAr[i - 1]) {
                    $("#highestVoltageNum" + i).html(highVoltageNumAr[i - 1] + "号/第" + highVoltageBoxAr[i - 1] + "箱");
                }
                if (highTemprtAr[i - 1]) {
                    $("#highestTempratureVal" + i).html(highTemprtAr[i - 1] + "℃");
                }
                if (highTemprtNumAr[i - 1] && highTemprtBoxAr[i - 1]) {
                    $("#highestTempratureNum" + i).html(highTemprtNumAr[i - 1] + "号/第" + highTemprtBoxAr[i - 1] + "箱");
                }
                if (lowVoltageAr[i - 1]) {
                    $("#lowestVoltageVal" + i).html(lowVoltageAr[i - 1] + "V");
                }
                if (lowVoltageNumAr[i - 1] && lowVoltageBoxAr[i - 1]) {
                    $("#lowestVoltageNum" + i).html(lowVoltageNumAr[i - 1] + "号/第" + lowVoltageBoxAr[i - 1] + "箱");
                }
                if (lowTemprtAr[i - 1]) {
                    $("#lowestTempratureVal" + i).html(lowTemprtAr[i - 1] + "℃");
                }
                if (lowTemprtNumAr[i - 1] && lowTemprtBoxAr[i - 1]) {
                    $("#lowestTempratureNum" + i).html(lowTemprtNumAr[i - 1] + "号/第" + lowTemprtBoxAr[i - 1] + "箱");
                }
            }
        }
    }

});